﻿using KBEngineTool.Core;
using System;
using System.IO;
using System.Xml.Serialization;

namespace KBEngineTool
{
    public class SlnConfig : Singleton<SlnConfig>
    {
        /// <summary>
        /// 工程目录
        /// </summary>
        public string assetFolder;

        /// <summary>
        /// types.xml
        /// </summary>
        public string typesXML;

        /// <summary>
        /// 目录entity_defs
        /// </summary>
        public string entityDefFolder;

        /// <summary>
        /// entities.xml
        /// </summary>
        public string entitiesXML;

        /// <summary>
        /// 目录user_type
        /// </summary>
        public string userTypeFolder;

        /// <summary>
        /// 默认配置文件
        /// </summary>
        public string defaultSettingXML;

        /// <summary>
        /// 当前工程配置文件
        /// </summary>
        public string settingXML;

        /// <summary>
        /// 工程自定义配置文件
        /// </summary>
        public string toolConfigFile;

        public bool IsEffective
        {
            get => File.Exists(typesXML) &&
                    Directory.Exists(entityDefFolder) &&
                    File.Exists(entitiesXML) &&
                    (File.Exists(defaultSettingXML) || File.Exists(settingXML));
        }
        public bool Load(string assetFolder)
        {
            this.assetFolder = assetFolder;
            this.typesXML = Path.Combine(assetFolder, @"scripts/entity_defs/types.xml");
            this.entityDefFolder = Path.Combine(assetFolder, @"scripts/entity_defs");
            this.entitiesXML = Path.Combine(assetFolder, @"scripts/entities.xml");
            this.userTypeFolder = Path.Combine(assetFolder, @"scripts/user_type");
            this.defaultSettingXML = Path.Combine(assetFolder, "../kbe/res/server/kbengine_defaults.xml");
            this.settingXML = Path.Combine(assetFolder, "res/server/kbengine.xml");
            this.toolConfigFile = Path.Combine(assetFolder, "ToolConfig.xml");
            return IsEffective;
        }
    }
}
